package com.edgarli.web.controller.detail;

import javax.servlet.http.HttpServletResponse;

import com.edgarli.detail.domain.TIncome;
import com.edgarli.detail.service.IIncomeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.edgarli.common.annotation.Log;
import com.edgarli.common.core.controller.BaseController;
import com.edgarli.common.core.domain.AjaxResult;
import com.edgarli.common.enums.BusinessType;
import com.edgarli.common.utils.poi.ExcelUtil;
import com.edgarli.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 家庭收入Controller
 * 
 * @author EdgarLi
 * @date 2022-01-12
 */
@RestController
@RequestMapping("/detail/income")
public class IncomeController extends BaseController
{
    @Autowired
    private IIncomeService incomeService;

    /**
     * 查询家庭收入列表
     */
    @PreAuthorize("@ss.hasPermi('detail:income:list')")
    @GetMapping("/list")
    public TableDataInfo list(TIncome income)
    {
        startPage();
        List<TIncome> list = incomeService.selectIncomeList(income);
        return getDataTable(list);
    }

    /**
     * 导出家庭收入列表
     */
    @PreAuthorize("@ss.hasPermi('detail:income:export')")
    @Log(title = "家庭收入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TIncome income)
    {
        List<TIncome> list = incomeService.selectIncomeList(income);
        ExcelUtil<TIncome> util = new ExcelUtil<TIncome>(TIncome.class);
        util.exportExcel(response, list, "家庭收入数据");
    }

    /**
     * 获取家庭收入详细信息
     */
    @PreAuthorize("@ss.hasPermi('detail:income:query')")
    @GetMapping(value = "/{incomeId}")
    public AjaxResult getInfo(@PathVariable("incomeId") Long incomeId)
    {
        return AjaxResult.success(incomeService.selectIncomeByIncomeId(incomeId));
    }

    /**
     * 新增家庭收入
     */
    @PreAuthorize("@ss.hasPermi('detail:income:add')")
    @Log(title = "家庭收入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TIncome income)
    {
        return toAjax(incomeService.saveOrUpdate(income));
    }

    /**
     * 修改家庭收入
     */
    @PreAuthorize("@ss.hasPermi('detail:income:edit')")
    @Log(title = "家庭收入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TIncome income)
    {
        return toAjax(incomeService.saveOrUpdate(income));
    }

    /**
     * 删除家庭收入
     */
    @PreAuthorize("@ss.hasPermi('detail:income:remove')")
    @Log(title = "家庭收入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{incomeIds}")
    public AjaxResult remove(@PathVariable Long[] incomeIds)
    {
        return toAjax(incomeService.deleteIncomeByIncomeIds(incomeIds));
    }
}
